import Vue from 'vue'

import Vuex from 'vuex'
import {
  setHttpConfig
} from '../utils/request'
import {
  parseJson
} from '../utils/util'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    //公共的变量，这里的变量不能随便修改，只能通过触发mutations的方法才能改变
    cityInfo: uni.getStorageSync('cityInfo') || {},
    userInfo: uni.getStorageSync('user') || {},
    messageActiveIndex: 0, // 消息 tab 栏激活的状态
    unreadMessageCount: 0,
    // 民辅警列表
    policeCheckboxValue: [],
    // 现场照片
    crimeImg: '',
    // 检查项数据
    radiovalue: [],
    // 证据信息
    evidenceList: [],
    // 检查项
    examineIdItems: []
  },
  mutations: {
    //相当于同步的操作
    SET_CITY_INFO(state, cityInfo) {
      state.cityInfo = {
        ...cityInfo
      }
      // 更新城市信息
      uni.setStorageSync('cityInfo', cityInfo)
      setHttpConfig()
    },
    SET_USER_INFO(state, userInfo) {
      state.userInfo = {
        ...userInfo
      }
    },
    SET_MESSAGE_ACTIVE_INDEX(state, index) {
      state.messageActiveIndex = index
    },
    SET_UNREAD_MESSAGE_COUNT(state, count) {
      state.unreadMessageCount = count
    },
    INIT_RADIOVALUE(state, value) {
      state.radiovalue = [
        ...value
      ]
    },
    INIT_EVIDENCE_LIST(state, value) {
      state.evidenceList = [
        ...value
      ]
    },
    SET_POLICE_CHECKBOX_VALUE(state, value) {
      state.policeCheckboxValue = [...value]
    },
    SET_CRIME_IMG(state, value) {
      state.crimeImg = value
    },
    SET_EXAMINE_ID_ITEMS(state, value) {
      state.examineIdItems = [...value]
    }
  },
  actions: {
    //相当于异步的操作,不能直接改变state的值，只能通过触发mutations的方法才能改变
  }
})
export default store